package com.example.seckillconsumer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author likaiping
 * @createTime 2024/7/7 14:56
 */
@Service
public class RedisMessagePublisher {

    @Resource
    private RedisTemplate redisTemplate;

    public void publishSeckillMessage(String goodsId) {
        redisTemplate.convertAndSend("seckill", goodsId);
        System.out.println("Published message: " + goodsId + " to channel: seckill");
        System.out.println("发布消息: " + goodsId + " 到频道: seckill");
    }
}